﻿using System;
using System.Threading;
using Android.App;
using Android.Content;
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using NorthStar.Passenger.Application;

using RestSharp;
using TheNorthStar.Api.Results;

namespace NorthStar.Passenger
{
    [Activity(Label = "MyDriver", MainLauncher = true, Icon = "@drawable/icon")]
    public class HomeActivity : Activity
    {
        int count = 1;
        

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            ImageButton bookTaxiBtn = FindViewById<ImageButton>(Resource.Id.BookTaxi);
            ImageButton callAdminBtn = FindViewById<ImageButton>(Resource.Id.CallAdminBtn);
            ImageButton myBookingsBtn = FindViewById<ImageButton>(Resource.Id.MyBookingsBtn);
            Button viewPrefsBtn = FindViewById<Button>(Resource.Id.BtnViewPrefs);
            ImageButton taxiMapBtn = FindViewById<ImageButton>(Resource.Id.TaxiMapBtn);
            //TextView debugMsg = FindViewById<TextView>(Resource.Id.debugMsg);

            viewPrefsBtn.Click += (sender, e) =>
                                      {
                                          StartActivity(typeof(PreferencesActivity));
                                      };

            bookTaxiBtn.Click += (sender, e) =>
                                     {
                                         StartActivity(typeof(BasicBookTaxiActivity));
                                     };

            callAdminBtn.Click += (sender, e) =>
                                      {
                                          Intent callIntent = new Intent(Intent.ActionCall);
                                          callIntent.SetData(Android.Net.Uri.Parse("tel:0262123456"));
                                          StartActivity(callIntent);
                                      };
            myBookingsBtn.Click += (sender, e) =>
                                       {
                                           StartActivity(typeof(MyBookingActivity));
                                       };

            taxiMapBtn.Click += (sender, e) =>
                                    {
                                        StartActivity(typeof (TaxiMapActivity));
                                    };

            string source = Intent.GetStringExtra("source") ?? "";
            if(!string.IsNullOrEmpty(source))
            {
                switch(source)
                {
                    case "cancelBooking":
                        Toast.MakeText(this, "Booking Cancelled" , ToastLength.Long).Show();
                        break;
                    case "driverRating":
                        Toast.MakeText(this, "Rating submitted. Thanks for the feedback", ToastLength.Short).Show();
                        break;
                }
            }

            StartService(new Intent(this, typeof(NorthStarBackgroundService)));

       
        }

      
    }
}

